"use strict";

/**
 * @ngdoc filter
 * @name jgappApp.filter:getkey
 * @function
 * @description
 * # getkey
 * Filter in the jgappApp.
 */
angular
  .module("jgappApp")
  .filter("getkey", function($filter) {
    return function(input, key) {
      var data = [];
      if (input) {
        if (Array.isArray(input)) {
          input.forEach(function(item, index) {
            data.push($filter("getkey")(item, key));
          });
        } else {
          data = input[key];
        }
      }
      return data.toString();
    };
  })
  .filter("arrfilter", function() {
    return function(input) {
      var data;
      if (input) {
        data = input.split(",");
      }
      return data;
    };
  })
  .filter("listvalueFmt", function($filter) {
    return function(input, fmt) {
      var data;
      if (input) {
        if (fmt && fmt == "Date") {
          data = $filter("dateFmt")(input);
        } else if (fmt && fmt == "Number") {
          data = $filter("NBFmt")(input);
        } else {
          data = input;
        }
      }
      return data;
    };
  })
  .filter("getnamefromvalue", function() {
    var datalist = [
      {
        key: "工程款",
        value: 1
      },
      {
        key: "垫付款",
        value: 2
      },
      {
        key: "保证金",
        value: 3
      },
      {
        key: "押金",
        value: 4
      },
      {
        key: "缴纳",
        value: 5
      },
      {
        key: "成本",
        value: 6
      },
      {
        key: "收入",
        value: 7
      },
      {
        key: "预借款",
        value: 8
      },
      {
        key: "清账款",
        value: 9
      },
      {
        key: "已付款",
        value: 10
      }
    ];
    return function(input) {
      var data;
      if (input) {
        data = datalist.filter(function(item) {
          return item.value == input;
        })[0].key;
      }
      return data;
    };
  });
